﻿#ifndef _DATABASE_VECTOR_SOURCE_H_H_
#define _DATABASE_VECTOR_SOURCE_H_H_

#include "udatabase/dll_cfg.h"
#include "udatabase/spatialDB/databasedatasource.h"
#include "udatabase/geodb/vectorfeatureclass.h"
//#include "udatabase/spatialDB/networkbuilder.h"
//#include "udatabase/spatialDB/networkdataset.h"
#include "udatabase/interface/ifields.h"
#include "udatabase/interface/igeometryfield.h"
#include "udatabase/sqldatabase.h"
//#include "annotation/annofeatureclass.h"
//#include "annotation/annotationbuilder.h"
#include "graphicengine/OgreCommon.h"

namespace FD
{
	namespace Utility
	{
		namespace DB
		{
			class CDatabaseVectorSourceImpl;
			/// <summary>
			/// 矢量数据源类
			/// </summary>
			class FD_DB_Export CDatabaseVectorSource : public FD::Utility::DB::CDatabaseDataSource
			{
				friend class CDatabaseVectorSourceFactory;
				friend class CVectorFeatureClass;
				friend class CDatabaseVectorSourceImpl;
			public:
				/// <summary>
				/// 默认析构函数
				/// </summary>
				~CDatabaseVectorSource();
			public:
				/// <summary>
				/// 获取数据源名称
				/// </summary>
				/// <param name=""></param>
				/// <returns>数据源名称</returns>
				virtual String getName() const;
				/// <summary>
				/// 获取数据源类型
				/// </summary>
				/// <param name=""></param>
				/// <returns>数据源类型</returns>
				virtual int32 getType() const;
				/// <summary>
				/// 获取数据源参数
				/// </summary>
				/// <param name=""></param>
				/// <returns>数据源KeyValue参数</returns>
				virtual   FD::Utility::DB::Interface::IPropertySet* getPropertySet() const;
				/// <summary>
				/// 判断数据源是否有效
				/// </summary>
				/// <param name=""></param>
				/// <returns>是，返回true;否则，返回false</returns>
				virtual bool isValid() const;
				/// <summary>
				/// 获取指定数据集类型的数据元信息
				/// </summary>
				/// <param name=""></param>
				/// <returns>数据元信息集合对象</returns>
				virtual   FD::Utility::DB::Interface::IDataMetaInfo* getDatasetInfo(const String &name);
				/// <summary>
				/// 获取指定数据集类型的数据元信息
				/// </summary>
				/// <param name=""></param>
				/// <returns>数据元信息集合对象</returns>
				virtual   FD::Utility::DB::Interface::IDataMetaInfos* getDatasetInfos(FD::Utility::DB::Interface::DatasetType type);

				/// <summary>
				/// 打开指定数据集名称的数据集
				/// </summary>
				/// <param name="name">指定名称</param>
				/// <returns>数据集对象指针，如果名字不存在，这返回null</returns>
				virtual FD::Utility::DB::Interface::IDataset * openDataset(const String& name);

				virtual bool closeDataset(FD::Utility::DB::Interface::IDataset* pDataset);
				/// <summary>
				/// 删除指定数据集名称的数据集
				/// </summary>
				/// <param name="name">指定名称</param>
				/// <returns>成功删除，返回true;否则，返回false</returns>
				virtual bool deleteDataset(const String& name);
				/// <summary>
				/// 创建FeatureClass数据集
				/// </summary>
				/// <param name=""></param>
				/// <returns>FD::Utility::DB::CVectorFeatureClass的指针</returns>
				FD::Utility::DB::CVectorFeatureClass* createFeatureClass(const String &name,FD::Utility::DB::Interface::IGeometryField &geofield,const FD::Utility::DB::Interface::IFields &fields);
				/// <summary>
				/// 打开FeatureClass数据集
				/// </summary>
				/// <param name=""></param>
				/// <returns>FD::Utility::DB::CVectorFeatureClass的指针</returns>
				FD::Utility::DB::CVectorFeatureClass* openFeatureClass(const String &name);
				/// <summary>
				/// 删除FeatureClass数据集
				/// </summary>
				/// <param name=""></param>
				/// <returns>成功删除，返回true;否则，返回false</returns>
				bool	deleteFeatureClass(const String &name);
				/// <summary>
				/// 获取网络数据集的创建者
				/// </summary>
				/// <param name=""></param>
				/// <returns>成功，返回有效指针;否则，返回NULL</returns>
				//FD::Utility::DB::CNetworkDatasetBuilder* getNetworkDatasetBuilder();
				/// <summary>
				/// 打开网络数据集
				/// </summary>
				/// <param name=""></param>
				/// <returns>成功，返回有效指针;否则，返回NULL</returns>
				//FD::Utility::DB::CNetworkDataset* openNetworkDataset(const String &name);
				/// <summary>
				/// 删除网络数据集
				/// </summary>
				/// <param name=""></param>
				/// <returns>成功，返回true;否则，返回False</returns>
				bool deleteNetworkDataset(const String &name);
				/// <summary>
				/// 打开标注数据集
				/// </summary>
				/// <param name=""></param>
				/// <returns>成功，返回有效指针;否则，返回NULL</returns>
				//FD::Utility::DB::CAnnoFeatureClass* openAnnoDataset(const String &name);
				/// <summary>
				/// 序列化字符串
				/// </summary>
				/// <param name=""></param>
				/// <returns></returns>
				virtual String toXML() const;
				/// <summary>
				/// 深度拷贝
				/// </summary>
				/// <param name=""></param>
				/// <returns></returns>
				virtual   FD::Utility::DB::Interface::IDataSource* clone() const;
				/// <summary>
				/// 数据源是否正在被编辑
				/// </summary>
				/// <returns>如果是返回true；否则返回false</returns>
				virtual bool IsEditing() const;				

			private:
				/// <summary>
				/// 开始编辑，用于标识数据集处在编辑状态，并根据参数，设置相关编辑对象。
				/// </summary>
				/// <param name="withUndo">确定是否开启Undo功能</param>
				/// <returns>开启编辑成功，返回true；否则，返回false</returns>
				bool beginEditing(const String &name);
				/// <summary>
				/// 结束编辑，用于标识数据集结束编辑，根据参数，确实是否保存数据。
				/// </summary>
				/// <param name="isSave">需要保存编辑数据，设置true;否则，设置false</param>
				/// <returns>结束编辑成功，返回true;否则，返回false</returns>
				bool endEditing(const String &name,bool isSave);

			protected:
				CDatabaseVectorSource(const String &srcname,const FD::Utility::DB::CSqlDatabase &db,const String& dbType);
				/// <summary>
				/// 初始化数据源的基本表
				/// </summary>
				/// <param name=""></param>
				/// <returns>void</returns>
				void init();

			private:
				String	m_SrcName;
				String	m_fullpath;
				vector<FD::Utility::DB::Interface::IDataset*> m_DatasetList;
				CDatabaseVectorSourceImpl *m_impl;
			};
		}
	}
} // End of namespaces

#endif //_DATABASE_VECTOR_SOURCE_H_H_

